<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="service.ErrorService"
	import="dto.TournamentDTO" import="dto.ParticipantListDTO"
	import="java.util.List"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
	ErrorService error = (ErrorService) request.getAttribute("error");
%>
<%
	TournamentDTO tDTO = (TournamentDTO) request
			.getAttribute("Tournament");
%>
<%
	Integer teamCount = (Integer) request.getAttribute("teamCount");
%>
<%
	Boolean participant = (Boolean) request.getAttribute("participant");
%>

<%
	String format = "";
	switch (tDTO.getFormat()) {
	case 1:
		format = "Single Elimination";
		break;
	case 2:
		format = "Double Elimination";
		break;
	}
%>

<%
	String type = "";
	switch (tDTO.getType()) {
	case 0:
		type = "Open";
		break;
	case 1:
		type = "Invitational";
		break;
	}
%>

<%
	String status = "";
	switch (tDTO.getStatus()) {
	case 0:
		status = "Not started";
		break;
	case 1:
		status = "Started";
		break;
	case 2:
		status = "Finished";
		break;
	}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>View Tournament</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.css" rel="stylesheet">
<style type="text/css"></style>
</head>

<body>
	<div class="container">
		<div class="header">
			<ul class="nav nav-pills pull-right">
				<%@include file="/WEB-INF/user/menu.jsp"%>
			</ul>
			<h2 class="text-muted">Tournament Hosting</h2>
			<hr>
		</div>
	</div>
	


	<div class="container" style="padding-bottom: 2px">

		<div class="list-group col-md-6 ">
			<%
				if (participant != null)
					out.print("You are participant in this tournament");
				else
					out.print("You do not participate in this tournament");
			%>
			<%
				if (error != null)
					out.println(error.getError());
			%>
		</div>


		<div class="pull-right ">
			<form action="TournamentSelector" method="post">

				<input type="hidden" class="form-control" name="id"
					value="<%=tDTO.getId()%>">

				<%
					if (participant != null)
						out.print("<input class=\"btn btn-md btn-primary\" type=\"submit\" name=\"leaveButton\" value=\"Leave\" />");
					else
						out.print("<input class=\"btn btn-md btn-primary\" type=\"submit\" name=\"joinButton\" value=\"Join\" />");
				%>
			</form>
		</div>
	</div>

	<div class="container" style="padding-top: 52px">
		<div>
			<table class="table table-bordered">
				<thead>
					<th>Tournament Name</th>
					<th>Sport</th>
					<th>Type</th>
					<th>Format</th>
					<th>Starting Date</th>
					<th>Participants</th>
					<th>Status</th>
				</thead>
				<tbody>
					<tr>
						<td>
							<%
								out.print(tDTO.getTournamentName());
							%>
						</td>
						<td>
							<%
								out.print(tDTO.getSport());
							%>
						</td>
						<td>
							<%
								out.print(type);
							%>
						</td>
						<td>
							<%
								out.print(format);
							%>
						</td>
						<td>
							<%
								out.print(tDTO.getStartDate());
							%>
						</td>
						<td>
							<%
								out.print(teamCount + " / " + tDTO.getMaxParticipants());
							%>
						</td>
						<td>
							<%
								out.print(status);
							%>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>

	<div class="container">
		<div class="col-md-6" style="padding-bottom: 20px">
			<%
				if (request.getAttribute("placementList") != null) {
					out.print("<h2>Placementlist</h2>");
					out.print("<div id=\"inner-content-div\">");
					out.print("<ul>");
					out.print(request.getAttribute("placementList"));
					out.print("</ul>");
					out.print("</div>");
				} else {
					out.print("<h2>Participants</h2>");
					out.print("<div id=\"inner-content-div\">");
					out.print("<ul>");
					out.print(request.getAttribute("teamList"));
					out.print("</ul>");
					out.print("</div>");
				}
			%>
		</div>
		<div class="col-md-6">
			<h2>Tournament Info</h2>
			<p>
				<%
					out.print(tDTO.getInfo());
				%>
			</p>
		</div>
	</div>

</body>
</html>